package com.sinoeyes.agreement.service.impl;

import com.sinoeyes.agreement.filter.AgreementFilter;
import com.sinoeyes.agreement.mapper.AgreementMapper;
import com.sinoeyes.agreement.po.AgreementPo;
import com.sinoeyes.agreement.service.IAgreementService;
import com.sinoeyes.agreement.vo.AgreementQueryVO;
import com.sinoeyes.common.core.page.RestPageResult;
import com.sinoeyes.common.core.text.Convert;
import com.sinoeyes.common.utils.DateUtils;
import com.sinoeyes.common.vo.BaseVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 协议信息Service业务层处理
 *
 * @author thse.SH
 * @date 2019-09-10
 */
@Service
public class AgreementServiceImpl implements IAgreementService {
    @Autowired
    private AgreementMapper agreementMapper;

    /**
     * 查询协议信息
     *
     * @param id 协议信息ID
     * @return 协议信息
     */
    @Override
    public AgreementQueryVO selectAgreementById(String id) {
        return  BaseVo.copyPo2Vo(agreementMapper.selectAgreementById(id), AgreementQueryVO.class) ;
    }

    @Override
    public RestPageResult selectAgreementList(AgreementFilter agreementFilter) {
        agreementFilter.startPage();
        List<AgreementQueryVO> agreementList = agreementMapper.selectAgreementList(agreementFilter);
        return BaseVo.copyPo2Vo(agreementFilter.getPageResult(agreementList), AgreementQueryVO.class);
    }

    /**
     * 新增协议信息
     *
     * @param agreementQueryVO 协议信息
     * @return 结果
     */
    @Override
    public int insertAgreement(AgreementQueryVO agreementQueryVO) {
        return agreementMapper.insertAgreement(BaseVo.copyVo2Po(agreementQueryVO, AgreementPo.class));
    }

    /**
     * 修改协议信息
     *
     * @param agreementQueryVO 协议信息
     * @return 结果
     */
    @Override
    public int updateAgreement(AgreementQueryVO agreementQueryVO) {
        return agreementMapper.updateAgreement(BaseVo.copyVo2Po(agreementQueryVO, AgreementPo.class));
    }

    /**
     * 删除协议信息对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteAgreementByIds(String ids) {
        return agreementMapper.deleteAgreementByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除协议信息信息
     *
     * @param id 协议信息ID
     * @return 结果
     */
    @Override
    public int deleteAgreementById(String id) {
        return agreementMapper.deleteAgreementById(id);
    }
}
